// packagesA/pages/hotplace/hotdeatil/index.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 500,
    hotplace: [],
    hotdetail:{},
    hotid:0,
    scrollTop:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getplace()
    this.setData({
      hotid:options.id
    })
  },
  replaceSpecialChar(content) {
    
    var regex = new RegExp('<img','gi' )
    var delImgStyleReg =/(?<=\" )style=\".*?\"/gi;
    content = content.replace(delImgStyleReg, '')
    content = content.replace(regex, '<img style="width: 100%  !important";height:"auto  !important"')
    return content;

  },
  //获取热门景点
  getplace() {
    let that = this
    wx.request({
      url: app.globalData.baseAPI + '/hot/hotdata',
      method: 'GET',

      header: {
        'content-type': 'application/json',
        'authorization': wx.getStorageSync('token'),
      },
      success(res) {
        if (!res.data.status) {
          res.data.data.forEach(val => {
            val.imglist=JSON.parse(val.imglist)
            val.position=JSON.parse(val.position)
            val.content=that.replaceSpecialChar(val.content)
            if(that.data.hotid==val.id){
              that.setData({
                hotdetail: val
              })
            }
          })
          that.setData({
            hotplace: res.data.data
          })
        }
      }
    })
  },
  // 滚动事件监听
  onPageScroll(e) {
    this.setData({
      scrollTop: e.scrollTop,
    })
  },

  gonavigation(){
    let latitude=this.data.hotdetail.position.lat
    let longitude=this.data.hotdetail.position.lng
    wx.openLocation({
      latitude,
      longitude,
      name:this.data.hotdetail.location,
      scale: 15
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})